#include<iostream>
#include<string>
#include <vector>
using namespace std;
class Solution0 {
public:
    bool backspaceCompare(string s, string t) {
        string s1,t1;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]=='#')
            {
                if(!s1.empty())
                    s1.pop_back();
                else continue;
            }
            else
                s1.push_back(s[i]);
        }
        for(int j=0;j<t.size();j++)
        {   
            if(t[j]=='#')
            {
                if(!t1.empty())
                    t1.pop_back();
                else continue;
            }
            else 
                t1.push_back(t[j]);
        }
        return t1==s1;
    }
};
class Solution {
public:
    bool backspaceCompare(string s, string t) {
        string s1,t1;
        for(int i=0;i<s.size();i++)
        {
            if(s[i]!='#')s1.push_back(s[i]);
            else if(!s1.empty())
                s1.pop_back();
        }
        for(int j=0;j<t.size();j++)
        {   
            if(t[j]!='#')t1.push_back(t[j]);
            else if(!t1.empty())
                t1.pop_back();
        }
        return t1==s1;
    }
};